package leetcode.code2090;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int[] getAverages(int[] nums, int k) {
		int len = nums.length;
		long[] sums = new long[len];
		sums[0] = nums[0];
		for (int i = 1; i < len; i++) {
			sums[i] = sums[i - 1] + (long) nums[i];
		}
		int[] ans = new int[len];
		for (int i = 0; i < len; i++) {
			int l = i - k, r = i + k;
			if (l < 0 || r >= len) {
				ans[i] = -1;
			} else {
				long sum = l - 1 < 0 ? sums[r] : sums[r] - sums[l - 1];
				ans[i] = (int) (sum / ((k << 1) + 1));
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
